#pragma once

#include "../../IMainFrame.h"
#include "TabBar.h"
#include <QWidget>
#include <QMap>

class TitleBar;
class TabBar;
class StatusBar;
class ContentWidget;
class WidgetResizer;
class SBaseDialog;
class QTimer;
class MainFrame : public QWidget, public IMainFrame
{
	Q_OBJECT
public:
	MainFrame();
	~MainFrame() = default;

	bool eventFilter(QObject *watched, QEvent *event) override;

	// 通过 IMainFrame 继承
	int existCmdWindow(int cmdId, const QString& params, bool enableParam = true) override;
	int openCmdWindow(int cmdId, const QString& params, QWidget* widget, const QString& title, bool popup = false) override;
	void activateCmdWindow(int tabId) override;
	void updateWindowTitle(int windowId, const QString& title) override;

	virtual void setNetworkStatus(int status) override;
	virtual void setMsgCenterNotify(int count) override;
	virtual void setCommonPageNotify(int* ids, int size, int ntype) override;
	virtual void setIasMenuNotify(const QString& iasmenu) override;
	KeySearchWidget* searchWidget() override;
	QWidget* cmdWindow(int tabid) override;

	TabBar* tabBar() const { return m_tabBar; }
	void setTabBar(TabBar* tb) { m_tabBar = tb; }

	float uiScale() const { return m_uiScale; }

protected:
	void paintEvent(QPaintEvent* event) override;

signals:
	void scaleChanged(float scale);
	void setConfigAuth(int* ids, int size);
	void setCommonPage(int* ids, int size, int ntype);
private slots:
	void onTabClose(int tabId);
	void onTabActivated(int newId);
	void onTabSeperated(CmdWindowInfo ti);
	void onPopupMoving(SBaseDialog* dlg);
	void onPoupuClosed();
	void onRelationCmdClick();
	void openHome();

private:
	void initializeCmdRelations();
	void updateRelationBar(int activeCmd);
	void closeWindow(int wid);
	void onScaleChanged(float scale);

private:
	TitleBar*	m_title = nullptr;
	TabBar*		m_tabBar = nullptr;
	//StatusBar* m_statusBar = nullptr;
	QWidget* m_relatedCmdBar = nullptr;
	ContentWidget* m_contentWidget = nullptr;
	QWidget* m_curContentChild = nullptr;
	WidgetResizer* m_resizer = nullptr;
	QMap<int, CmdWindowInfo>	m_cmdWindows;//place it in command mgr?<winid, cmdinf>
	QTimer* m_timeTimer = nullptr;
	QVector<QVector<int> >	m_relationCmds;
	QVector<int> m_curRelations;
	float		m_uiScale = 1;
};
